package idv.cjcat.stardust.common.math;
	
	/**
	 * This class provides common mathematical constants and methods.
	 */
	public class StardustMath {
		
		public static final double HALF_PI = 0.5 * Math.PI;
		public static final double TWO_PI = 2 * Math.PI;
		public static final double DEGREE_TO_RADIAN = Math.PI / 180;
		public static final double RADIAN_TO_DEGREE = 180 / Math.PI;
		
		/**
		 * Clamps a value within bounds.
		 * @param	input
		 * @param	lowerBound
		 * @param	upperBound
		 * @return
		 */
		public static double clamp(double input, double lowerBound, double upperBound) {
			if (input < lowerBound) return lowerBound;
			if (input > upperBound) return upperBound;
			return input;
		}
		
		/**
		 * Interpolates linearly between two values.
		 * @param	x1
		 * @param	y1
		 * @param	x2
		 * @param	y2
		 * @param	x3
		 * @return
		 */
		public static final double interpolate(double x1, double y1, double x2, double y2, double x3) {
			return y1 - ((y1 - y2) * (x1 - x3) / (x1 - x2));
		}
		
		/**
		 * The remainder of value1 divided by value2, negative value1 exception taken into accound. 
		 * Value2 must be positive.
		 * @param	value1
		 * @param	value2
		 */
		public static int mod(int value1, int value2){
			int remainder = value1 % value2;
			return (remainder < 0)?(remainder + value2):(remainder);
		}
		
		public static int randomFloor(int num) {
			int floor = num | 0;
			return floor + (int) (((num - floor) > Math.random())?(1):(0));
		}
	}
